<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>模板的分离写法</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
  </head>

  <body>
    <div id="app">
      <cpn1></cpn1>
      <cpn2></cpn2>
      <cpn2></cpn2>
    </div>
    <!-- 使用script定义html模板 -->
    <script type="text/x-template" id="cpn1">
      <div>
          <h1>组件</h1>
          <p>哈哈哈哈哈</p>
      </div>
    </script>
    <!-- template标签定义html模板 -->
    <template id="cpn2">
      <div>
        <h1>{{tital}}</h1>
        <p>哈哈哈哈哈</p>
        <h2>{{message}}</h2>
        <button @click="addclick">点击</button>
      </div>
    </template>
    <script>
      Vue.component("cpn2", {
        template: "#cpn2",
        data() {
          return {
            tital: "abc",
            message: "0",
          };
        },
        methods: {
          addclick() {
            this.message++;
          },
        },
      });
      //创建Vue实例,得到 ViewModel
      var app = new Vue({
        el: "#app",
        data: {},
        methods: {},
        components: {
          cpn1: {
            template: "#cpn1",
          },
        },
      });
    </script>
  </body>
</html>
